package com.xinqi.modules.course.course.enums;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue;
import com.xinqi.common.base.annotations.Describe;
import com.xinqi.common.base.enums.BaseEnum;
import lombok.Getter;

import java.util.Objects;

/**
 * @author wenjie
 * @date 2023/9/14  18:15
 */
@Describe("关系枚举")
public enum ClassStudentRelationshipEnum implements BaseEnum {
    虚拟主学生("MASTER", "虚拟主学生"),
    本人("OWNER", "本人"),
    爸爸("FATHER", "爸爸"),
    妈妈("MOTHER", "妈妈"),
    爷爷("GRANDFATHER", "爷爷"),
    奶奶("GRANDMOTHER", "奶奶"),
    叔叔("UNCLE", "叔叔"),
    阿姨("AUNT", "阿姨"),
    哥哥("BROTHER", "姑姑"),
    姐姐("SISTER", "姑父"),
    家长("PARENT", "家长");

    @Getter(onMethod_ = {@JsonValue})
    private final String code;

    @Getter
    private final String describe;

    ClassStudentRelationshipEnum(String code, String describe) {
        this.code = code;
        this.describe = describe;
    }

    @JsonCreator
    public static ClassStudentRelationshipEnum of(String code) {
        return BaseEnum.of(ClassStudentRelationshipEnum.class, code);
    }

    public static ClassStudentRelationshipEnum to(String describe) {
        if (describe == null) {
            return null;
        }

        for (ClassStudentRelationshipEnum value : ClassStudentRelationshipEnum.values()) {
            if (Objects.equals(value.getDescribe(), describe)) {
                return value;
            }
        }

        return null;
    }
}
